package com.smarttiger.zero.admin.service;

import com.smarttiger.zero.admin.dao.ArgsDao;
import com.smarttiger.zero.admin.dao.InterfaceArgsDao;
import com.smarttiger.zero.admin.dao.InterfaceDao;
import com.smarttiger.zero.admin.dao.LogicDao;
import com.smarttiger.zero.admin.entity.InterfaceArgsModel;
import com.smarttiger.zero.admin.entity.InterfaceModel;
import com.smarttiger.zero.admin.util.ParamNames;
import com.smarttiger.zero.admin.webservice.WebServiceConfig;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class InterfaceArgsService extends BaseService<InterfaceArgsModel>{
    @Autowired
    InterfaceArgsDao iargsDao;

    @Autowired
    InterfaceDao interfaceDao;

    @Autowired
    @Qualifier("endpointList")
    Map<String,EndpointImpl> endpointMap;

    @Autowired
    @Qualifier(Bus.DEFAULT_BUS_ID)
    SpringBus springBus;

    @Autowired
    ArgsDao argsDao;

    @Autowired
    InterfaceArgsDao interfaceArgsDao;

    @Autowired
    LogicDao logicDao;

    @Autowired
    WebServiceConfig webServiceConfig;

    @PostConstruct
    public void initMethod(){
        super.setDao(iargsDao);
    }

    @ParamNames("interfaceId")
    public List<InterfaceArgsModel> findIArgsByInterfaceId(String id){
        return iargsDao.findAllByInterfaceId(id);
    }


    @Override
    public void save(InterfaceArgsModel u) {
        InterfaceModel in = interfaceDao.findById(u.getInterfaceId()).get();
        webServiceConfig.stopWS(in);
        super.save(u);
        Optional<InterfaceModel> interfaceModel = interfaceDao.findById(u.getInterfaceId());
        InterfaceModel model = interfaceModel.get();
    }

    @Override
    public void update(InterfaceArgsModel u) {
        InterfaceModel in = interfaceDao.findById(u.getInterfaceId()).get();
        webServiceConfig.stopWS(in);
        super.update(u);
        Optional<InterfaceModel> interfaceModel = interfaceDao.findById(u.getInterfaceId());
        InterfaceModel model = interfaceModel.get();
    }

    @Override
    public void delete(String id) {
        InterfaceArgsModel u = findById(id).get(0);
        InterfaceModel in = interfaceDao.findById(u.getInterfaceId()).get();
        webServiceConfig.stopWS(in);
        super.delete(id);
        Optional<InterfaceModel> interfaceModel = interfaceDao.findById(u.getInterfaceId());
        InterfaceModel model = interfaceModel.get();

    }





}
